<%@ page language="java" import="weaver.conn.RecordSet" pageEncoding="UTF-8" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.resource.ResourceComInfo" %>
<%@ page import="weaver.soa.workflow.request.MainTableInfo" %>
<%@ page import="weaver.soa.workflow.request.Property" %>
<%@ page import="weaver.soa.workflow.request.RequestInfo" %>
<%@ page import="weaver.soa.workflow.request.RequestService" %>
<%@ page import="weaver.workflow.request.RequestComInfo" %>
<%@ page import="weaver.workflow.workflow.WorkflowComInfo" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="weaver.general.BaseBean" %>
<script>

</script>
<%

    BaseBean baseBean = new BaseBean();
    baseBean.writeLog( "-------WorkflowCreateByRequestMap---------" );
    String creatorId = "1";
    String workflowId = "913";//流程ID
    String requestName = "供应商冻结、解冻审核流程";//流程名称
    String IsNextFlow = "0";//是否提交下一节点
    Map<String, String> requestMainMap = new HashMap<String, String>();
    String requestid = WorkflowCreateByRequestMap(creatorId,workflowId,requestName,IsNextFlow,requestMainMap);
    out.println( requestid );
%>
<%!
    public static String WorkflowCreateByRequestMap(String creatorId, String workflowId, String requestName, String IsNextFlow, Map<String, String> requestMainMap) {
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog( "-------WorkflowCreateByRequestMap---------" );
        baseBean.writeLog( ">>>>>creatorId:" + creatorId );
        baseBean.writeLog( ">>>>>workflowId:" + workflowId );
        baseBean.writeLog( ">>>>>requestName:" + requestName );
        baseBean.writeLog( ">>>>>IsNextFlow:" + IsNextFlow );
        RecordSet rs = new RecordSet();
        rs.execute( "select (case when activeVersionID is null then id else activeVersionID end) as wfid   from workflow_base where id=" + workflowId );
        rs.next();
        workflowId = Util.null2String( rs.getString( "wfid" ) );

        String requestid = "";
        RequestInfo requestInfo = new RequestInfo();
        requestInfo.setCreatorid( creatorId );//
        requestInfo.setWorkflowid( workflowId );//
        requestInfo.setDescription( requestName );//
        if ("0".equals( IsNextFlow )) {
            requestInfo.setIsNextFlow( IsNextFlow );
        }

        MainTableInfo mainTableInfo = new MainTableInfo();
        Property[] propertyArray = new Property[requestMainMap.size()];
        int p = 0;
        for (Map.Entry<String, String> entry : requestMainMap.entrySet()) {
            propertyArray[p] = new Property();
            propertyArray[p].setName( Util.null2String( entry.getKey() ) );
            propertyArray[p].setValue( Util.null2String( entry.getValue() ) );
            baseBean.writeLog( "\r\n---p=" + p + "---Key=" + entry.getKey() + "---Value=" + entry.getValue() );
            p++;
        }
        baseBean.writeLog( "-----csp=" + p );
        mainTableInfo.setProperty( propertyArray );
        requestInfo.setMainTableInfo( mainTableInfo );

        RequestService service = new RequestService();
        try {
            try {
                requestid = service.createRequest( requestInfo );
            } catch (Exception e) {
                baseBean.writeLog( "=======" + e.getMessage() );
            }
            StringBuffer sbf = new StringBuffer( "\r\n-----start" );
            WorkflowComInfo wfcif = new WorkflowComInfo();
            RequestComInfo rcif = new RequestComInfo();
            ResourceComInfo rscif = new ResourceComInfo();
            sbf.append( "\r\n-----姓名:" + rscif.getLastname( rcif.getRequestCreater( requestid ) ) );
            sbf.append( "\r\n-----时间:" + rcif.getRequestCreateTime( requestid ) );
            sbf.append( "\r\n-----创建流程:" + wfcif.getWorkflowname( workflowId ) );
            sbf.append( "\r\n-----请求:" + rcif.getRequestname( requestid ) );
            sbf.append( "\r\n-----请求:" + requestid );
            sbf.append( "\r\n-----创建工作流记录日志结束" );
            baseBean.writeLog( sbf.toString() );
        } catch (Exception e) {
            baseBean.writeLog( "e:" + e );
        }
        return requestid;
    }
%>